package com.ruoyi.camp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.camp.domain.CampFacility;
import com.ruoyi.camp.service.ICampFacilityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 营地设施Controller
 * 
 * @author ruoyi
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/camp/campfacility")
public class CampFacilityController extends BaseController
{
    @Autowired
    private ICampFacilityService campFacilityService;

    /**
     * 查询营地设施列表
     */
    @PreAuthorize("@ss.hasPermi('camp:facility:list')")
    @GetMapping("/list")
    public TableDataInfo list(CampFacility campFacility)
    {
        startPage();
        List<CampFacility> list = campFacilityService.selectCampFacilityList(campFacility);
        return getDataTable(list);
    }

    /**
     * 导出营地设施列表
     */
    @PreAuthorize("@ss.hasPermi('camp:facility:export')")
    @Log(title = "营地设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CampFacility campFacility)
    {
        List<CampFacility> list = campFacilityService.selectCampFacilityList(campFacility);
        ExcelUtil<CampFacility> util = new ExcelUtil<CampFacility>(CampFacility.class);
        util.exportExcel(response, list, "营地设施数据");
    }

    /**
     * 获取营地设施详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:facility:query')")
    @GetMapping(value = "/{cfid}")
    public AjaxResult getInfo(@PathVariable("cfid") String cfid)
    {
        return success(campFacilityService.selectCampFacilityByCfid(cfid));
    }

    /**
     * 新增营地设施
     */
    @PreAuthorize("@ss.hasPermi('camp:facility:add')")
    @Log(title = "营地设施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CampFacility campFacility)
    {
        return toAjax(campFacilityService.insertCampFacility(campFacility));
    }

    /**
     * 修改营地设施
     */
    @PreAuthorize("@ss.hasPermi('camp:facility:edit')")
    @Log(title = "营地设施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CampFacility campFacility)
    {
        return toAjax(campFacilityService.updateCampFacility(campFacility));
    }

    /**
     * 删除营地设施
     */
    @PreAuthorize("@ss.hasPermi('camp:facility:remove')")
    @Log(title = "营地设施", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cfids}")
    public AjaxResult remove(@PathVariable String[] cfids)
    {
        return toAjax(campFacilityService.deleteCampFacilityByCfids(cfids));
    }
}
